import router from './router'
import store from './store'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
NProgress.configure({ showSpinner: false })
const pageList = ['/login']
router.beforeEach((to, from, next) => {
  document.title = `黑马面面---${to.meta.title}`
  NProgress.start()
  if (store.state.login.token) {
    if (to.path.toLowerCase() === '/login') {
      next('/')
    } else {
      next()
    }
  } else {
    // 要去的页面是  to.path
    // 白名单 pageList
    if (pageList.includes(to.path.toLowerCase())) {
      next()
    } else {
      next('/login')
    }
  }
})
router.afterEach((to, from, next) => {
  NProgress.done()
})
